package com.ljh.controller;


import com.ljh.pojo.Group;
import com.ljh.pojo.Xiaozu;
import com.ljh.service.IClazzService;
import com.ljh.service.IGroupService;
import com.ljh.service.IXiaozuService;
import com.ljh.vo.GroupVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lijiahao
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/xiaozu")
public class XiaozuController {


    @Autowired
    private IXiaozuService xiaozuService;
    @Autowired
    private IClazzService clazzService;

    @GetMapping
    public List<GroupVo> listAll(){
        List<Xiaozu> list = xiaozuService.list();
        ArrayList<GroupVo> groupVos = new ArrayList<>();
        for (Xiaozu xiaozu : list) {
            GroupVo groupVo = new GroupVo();
            BeanUtils.copyProperties(xiaozu,groupVo);
            groupVo.setClazz(clazzService.getById(xiaozu.getClazzId()));
            groupVos.add(groupVo);
        }
        return groupVos;
    }
}
